package com.zjkj.mp.vo.user;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.zjkj.mp.utils.security.SpringSecurityUtils;

/**
 * 
 * 手机平台用户信息表
 * 
 * @author <a href="mailto:409384898@qq.com">chenchen</a>
 * @history
 * <TABLE id="HistoryTable" border="1">
 * 	<TR><TD>时间</TD><TD>描述</TD><TD>作者</TD></TR>
 *	<TR><TD>2013-6-5</TD><TD>创建初始版本</TD><TD>chenchen</TD></TR>
 * </TABLE>
 */
public class  MpUser  implements UserDetails {

	private static final long serialVersionUID = -5912386566198716734L;

	private int  userId;
	/** 真实姓名 */
	private String realName;
	private String password;
	/** 邮箱 */
	private String email;
	/** 手机*/
	private String mobile;
	/** 电话*/
	private String phone;
	/** 生日*/
	private String birthDay;
	/** 单位*/
	private String unit;
	/** 地址*/
	private String address;
	/** 性别 */
	private String sex;
	/** 备注 */
	private String note;
	 
	private String userState;
	/** 角色ID */
	private int roleID;
	/** 账号创建时间 */
	private String createDate;	
	/** 短信余额*/
	private long balance;
	
	/**
	 * 此用户发送短信是否需要审核
	 * true，表示需要审核
	 * false，表示不需要审核
	 */
	private  boolean isAudit; 
	
	private Collection<? extends GrantedAuthority> authorities;

	/**
	 * 设置权限信息
	 * 
	 * @param Authorities
	 */
	public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
		this.authorities = authorities;
	}

	/**
	 * @see org.springframework.security.core.userdetails.UserDetails#getAuthorities()
	 */
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return this.authorities;
	}

	/**
	 * @see org.springframework.security.core.userdetails.UserDetails#isAccountNonExpired()
	 */
	public boolean isAccountNonExpired() {
		return true;
	}

	/**
	 * @see org.springframework.security.core.userdetails.UserDetails#isAccountNonLocked()
	 */
	public boolean isAccountNonLocked() {
		return true;
	}

	/**
	 * @see org.springframework.security.core.userdetails.UserDetails#isCredentialsNonExpired()
	 */
	public boolean isCredentialsNonExpired() {
		return true;
	}

	/**
	 * @see org.springframework.security.core.userdetails.UserDetails#isEnabled()
	 */
	public boolean isEnabled() {
		if (this.userState != null && this.userState.equals(USER_ZT.SYZ)) {
			return true;
		} else {
			return false;
		}
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	 

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserState() {
		return userState;
	}

	public void setUserState(String userZt) {
		this.userState = userZt;
	}

	public String getUsername() {
		return this.realName;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getBirthDay() {
		return birthDay;
	}

	public void setBirthDay(String birthDay) {
		this.birthDay = birthDay;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	 

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + userId;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MpUser other = (MpUser) obj;
		if (userId != other.userId)
			return false;
		return true;
	}

	public int getRoleID() {
		return roleID;
	}

	public void setRoleID(int roleID) {
		this.roleID = roleID;
	}

	public String getCreateDate() {
		return createDate;
	}

	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}


	
	/**
	 * 得到角色的名称
	 * @return
	 */
	public String getRoleName(){
		return UserRoles.getNameById(this.roleID);
	}
	
	/**
	 * 得到用户账号状态的名称
	 * @return
	 */
	public String getUserStateName(){
		return USER_ZT.getNameById(this.userState);
	}

	/**
	 * 此用户发送短信是否需要审核
	 * true，表示需要审核
	 * false，表示不需要审核
	 */
	public boolean isAudit() {
		return isAudit;
	}

	/**
	 * 此用户发送短信是否需要审核
	 * true，表示需要审核
	 * false，表示不需要审核
	 */
	public void setAudit(boolean isAudit) {
		this.isAudit = isAudit;
	}

	@Override
	public String toString() {
		return "MpUser [userId=" + userId + ", realName=" + realName
				+ ", password=" + password + ", email=" + email + ", mobile="
				+ mobile + ", phone=" + phone + ", birthDay=" + birthDay
				+ ", unit=" + unit + ", address=" + address + ", sex=" + sex
				+ ", note=" + note + ", userState=" + userState + ", roleID="
				+ roleID + ", createDate=" + createDate + ", isAudit="
				+ isAudit + ", authorities=" + authorities + "]";
	}
	
	
	/**
	 * 得到当前登录的用户
	 */
	public static MpUser getCurrentUser(){
		return (MpUser) SpringSecurityUtils.getCurrentUser();
	}

	public long getBalance() {
		return balance;
	}

	public void setBalance(long balance) {
		this.balance = balance;
	}
}

/**
 * Copyright © 2013,指尖科技 All rights reserved.
 */
